<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>用户信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <link rel="stylesheet" href="${ctx}/css/font.css">
    <link rel="stylesheet" href="${ctx}/lib/layui/css/layui.css">
    <link rel="stylesheet" href="${ctx}/css/xadmin.css">
    <script type="text/javascript" src="${ctx}/js/jquery.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/xadmin.js"></script>
    <script src="${ctx}/lib/layui/layui.js" charset="utf-8"></script>
  </head>
  <body>

  <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>课程评价</cite></a>
      </span>
  </div>
  <div class="x-body">

    <blockquote class="layui-elem-quote">
      <span class="x-red">你正在评价课程，请同学客观公正进行评价，学生的信息将会进行保密！</span>
    </blockquote>

  <table class="layui-table">
    <thead>
    <tr>
      <th>一级指标</th>
      <th>二级指标</th>
      <th>评价</th>
    </thead>
    </tbody>
      <c:forEach items="${requestScope.list}" var="list" varStatus="stat">
        <tr>
          <td>${list.target.name}</td>
          <td>${list.name}</td>
          <td><div class="test${stat.index + 1}"></div> <input class="num" hidden="hidden" id="content${stat.index + 1}"/></td>
          <script>
            layui.use(['rate'], function(){
              var rate = layui.rate;
              //基础效果
              var ins1 = rate.render({
                elem: '.test'+${stat.index+1}
                ,text: true
                ,setText: function(value){
                  var arrs = {
                    '1' : '极差'
                    ,'2': '较差'
                    ,'3': '中等'
                    ,'4': '良好'
                    ,'5': '优秀'
                  };
                  this.span.text(arrs[value]|| ("暂无"));
                }
                ,choose: function(value){
                 $("#content${stat.index+1}").val(ins1.config.value);
                }
              });
            });
          </script>
        </tr>

      </c:forEach>
  </table>
    <button type="button" class="layui-btn layui-btn-small" style="margin-left: 500px;margin-top: 30px;">提交</button>

    <script type="text/javascript">
      layui.use(['form'], function(){
        var layer = layui.layer;
        $(function () {
          $("button").click(function(){
            var array = new Array();
//          遍历input中的值
            $("input").each(function() {
              var value = $(this).val();
              if (value == null || value == "") {
                array.push(0);
              }
              array.push(value);
            });
            var result = $.inArray(0, array);
            if (result != -1){
              layer.alert(JSON.stringify("你还没有完成评价，请前往评价！"), {
                title: '警告'
              });
              return;
            }else {
              $.ajax({
                type: "post",
                url: "${ctx}/result",
                dataType:"json",
                data:{"array":array,"studentID":${scourse.studentID},"teacherID":${scourse.teacherID},"sourceID":${scourse.courseID}},
                async:false,
                traditional:true,
                success:function(){
                  // 成功之后，页面返回到课程评价页面
                  location.href="${ctx}/evaluate/clazz?userType=${sessionScope.user_session.userType}";
                }
              });
            }
          });
        });
      });
    </script>
  </div>
  </table>


  </body>


</html>